<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        h2 {
            text-align: center;
            color: #333;
        }

        .form-group {
            margin-bottom: 15px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #333;
        }

        input[type="text"], input[type="password"], input[type="email"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }

        button:hover {
            background-color: #0056b3;
        }

        .switch-form {
            text-align: center;
            margin-top: 15px;
        }

        .switch-form a {
            color: #007bff;
            text-decoration: none;
        }

        .switch-form a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<div class="container">
    <div id="registerForm">
        <h2>用户注册</h2>
        <form action="/jsp_war/registerServlet" method="post">
            <div class="form-group">
                <label for="registerUsername">用户名:</label>
                <input type="text" id="registerUsername" name="username" required>
                <div id="checkUserName"></div>
            </div>

            <div class="form-group">
                <label for="registerPassword">密码:</label>
                <input type="password" id="registerPassword" name="password" required>
                <div id="checkPassword"></div>
            </div>
            <div class="form-group">
                <label for="confirmPassword">确认密码:</label>
                <input type="password" id="confirmPassword" name="confirmPassword" required>
                <div id="checkConfirmPassword"></div>
            </div>
            <button type="submit">注册</button>
        </form>
        <div class="switch-form">
            已有账户? <a href="login.html">立即登录</a>
        </div>
    </div>
</div>


<script>
    var registerUserName = document.querySelector("#registerUsername");
    var registerEmail = document.querySelector("#registerEmail");
    var registerPassword1 = document.querySelector("#registerPassword");
    var registerPassword2 = document.querySelector("#confirmPassword");

    var checkUserName = document.querySelector("#checkUserName");
    var checkEmail = document.querySelector("#checkEmail");
    var checkPassword = document.querySelector("#checkPassword");
    var checkConfirmPassword = document.querySelector("#checkConfirmPassword");

  /*  function checkName() {
        if (/^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(registerUserName.value)) {
            checkUserName.innerHTML = "ok"
        } else {
            checkUserName.innerHTML = "erro"
        }
    }*/

    function CheckEmail() {
        if (/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(registerEmail.value)){
            checkEmail.innerHTML="ok"
        }else checkEmail.innerHTML="erro"
    }

    function CheckPassword() {
        if (/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/.test(registerPassword1.value)){
            checkPassword.innerHTML = "ok"
        }else checkPassword.innerHTML="erro"
    }

    function CheckEquals(){
        if (registerPassword1.value===registerPassword2.value){
            checkConfirmPassword.innerHTML="ok"
        }else checkConfirmPassword.innerHTML="erro"
    }

    registerUserName.addEventListener("blur", checkName)
    registerEmail.addEventListener("blur",CheckEmail)
    registerPassword1.addEventListener("blur",CheckPassword)
    registerPassword2.addEventListener("blur",CheckEquals)


</script>


</body>
</html>
